capture log close
log using replica_fig3_tab1_symb_1.log,replace

*       FIG3_SYMB_1.LOG

*       FIRST VERSION   SEPTEMBER 21, 2010
*       THIS VERSION    SEPTEMBER 21, 2010

*       LAST REVISOR    AI

*       INPUT FILE:             BASE12_6.DTA
*       OUTPUT FILE:            REPLICA FOR FIGURE 3 AND FOR TABLE 1
*

version 11.0

di "log file printed on $S_DATE at $S_TIME"


set more 1
clear
program drop _all
macro drop _all
scalar drop _all

# delimit ;

set scheme s1color;
set memory 300000; 
set matsize 250;
tempfile tmpf1 tmpf2 tmpf3 tmpf4;

use base12_6, clear;

* KEEP MEDIA PRIMO ANNO;
sort id anac;
qui by id: gen gpa_1 = gpa[1]; 

* lagged income and taxes;
gen ym1 = l1.y;
gen ydm1 = l1.yd;
gen tteom1 = l1.tteo;
gen tpaidm1 = l1.tpaid;

gen ym2 = l2.y;
gen ydm2 = l2.yd;
gen tteom2 = l2.tteo;
gen tpaidm2 = l2.tpaid;

gen ym3 = l3.y;
gen ydm3 = l3.yd;
gen tteom3 = l3.tteo;
gen tpaidm3 = l3.tpaid;


* STATISTICHE PER PANNELLO A DI TABELLA 1

tab fc if aniscr==1;

tab female fc if aniscr==1, col;

tab outmil fc if aniscr==1, col;

gen topvoto = votodi==1;
tab topvoto fc if aniscr==1, col;

bysort fc: sum y if aniscr==1;
sum y if aniscr==1;


* generate dummy liceo from  tipo diploma;
gen typedip =  cod_tit_dipl ==1 ;

tab typedip fc if aniscr==1, col;

gen topvl = votolau>110;
tab topvl fc if aniscr==1, col;

tab fc if aniscr==1;



* SELEZIONE DEL CAMPIONE;
* keep studenti in corso regolare al 4 anno;
keep if real_status==4&aniscr==4&posizione==14 ;



* STATISTICHE PER PANNELLO B DI TABELLA 1



tab fc if aniscr==1;

tab female fc if aniscr==4, col;

tab outmil fc if aniscr==4, col;

*gen topvoto = votodi==1;
tab topvoto fc if aniscr==4, col;

bysort fc: sum y if aniscr==4;
sum y if aniscr==4;


* generate dummy liceo from  tipo diploma;
*gen typedip =  cod_tit_dipl ==1 ;

tab typedip fc if aniscr==4, col;

*gen topvl = votolau>110;
tab topvl fc if aniscr==4, col;

tab fc if aniscr==4;





xtdes;


*******NEW
* restrizione della distanza dalla soglia;
keep if yd>-3&yd<3;

xtdes;





* VARIABILI NECESSARIE;

tab anac, gen(daa);

gen y2 = y*y;
gen y3 = y*y2;
gen y4 = y*y3;

label var y "Real income - thousands of Euros, base 2000";

tab fascia_teo, gen(dfa);

gen yd2 = yd*yd;
gen yd3 = yd2*yd;
gen yd4 = yd3*yd;

label var yd "Distance from nearest discontinuity in 1000 euros";


* ALTRE VARIABILI NECESSARIE PER ANALISI  RDD;


*generate for compliance analysis;
gen comp = tpaid>=tteo1;
label var comp "fraction with tpaid >tteo1";

* generate dummies for nearest discontinuity;
tab neardisc , gen(dnear);

* calcola gli scarti dalla media di anno/punto di discontinuit�

sort anac neardisc;
egen mtp=mean(tpaid), by(anac neardisc);
gen wtp=tpaid-mtp;
label var wtp "paid tuition in deviation from mean";



* VARIABILI PRE INTERVENTION;

* Normalizzazione del voto di matematica;
gen normat = (mat - 0)/(31-0);
sum normat votodip;
corr normat votodip;

* Normalizzazione del voto di statistica;
gen norsta = (sta - 0)/(31-0);
sum norsta votodip;
corr norsta votodip;

* Normalizzazione del gpa 1 anno;
gen norgpa1 = (gpa_1 - 0)/(31-0);
sum norgpa1 votodip;
corr norgpa1 votodip;



* altre variabili da usare nelle regressioni

outmil
female
votodip

;



# delimit cr


* analisi per soglia

local c = 1
di `c'

*forvalues i=1(1)10 {

forvalues i= 2(5) 7 {
di "regressioni per soglia " `i'


local cp1 = `c' + 1
di" c = "  `c'
di" cp1 = "  `cp1'


local c = `c' + 2

lowess fc yd if neardisc==`i', generate(fcsm`i') by(z) nograph mean
label var fcsm`i' "Smooth average"
sort neardisc yd
twoway line fcsm`i' yd if neardisc==`i' , ysc(r(0.7 0.9)) ylabel(0.7(0.05)0.9) xline(0) title("Prob. of fuori corso: disc = `i'" ) saving(fcsm`i', replace) 
graph export fcsm`i'.eps, replace logo(off)


lowess tpaid yd if neardisc==`i', generate(tpaidsm`i') by(z) nograph mean
label var tpaidsm`i' "t_paid"
lowess tteo yd if neardisc==`i', generate(tteosm`i') by(z) nograph mean
label var tteosm`i' "t_off"
sort neardisc yd
twoway line tpaidsm`i' yd if neardisc==`i'|| line tteosm`i' yd if neardisc==`i' , ysc(r(0.5 6)) ylabel(0.5(1)5.5) xline(0) title("Official and paid tuition: disc = `i'" ) saving(ftpaidsm`i', replace) legend(pos(10) ring(0)  stack symxsize(8) label(1 "{bf}{&tau}{sup:p}") label(2 "{bf}{&tau}{sup:t}") ) lpattern(--) l1(Smooth average)
graph export ftpaidsm`i'.eps, replace logo(off)


}



* grafici finali combinati


*figura per nber a 4 pannelli main effects
gr combine ftpaidsm2.gph fcsm2.gph ftpaidsm7.gph fcsm7.gph   , saving(fig_3, replace)
*graph export ffin_main_eff.eps, replace logo(off)
graph export fig_3.eps, replace logo(off)




log close






